package cn.wen233.srpc;

import cn.wen233.srpc.api.HelloService;
import cn.wen233.srpc.api.StudentService;
import cn.wen233.srpc.basic.model.ServerConfig;
import cn.wen233.srpc.basic.model.ServerInstance;
import cn.wen233.srpc.core.service.factory.ReferenceProxyFactory;
import cn.wen233.srpc.model.Book;
import cn.wen233.srpc.model.Student;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;

/**
 * @author wenei
 * @date 2021-10-27 16:49
 */
public class ClientTest {



    public static void main(String[] args) {
//        HelloService helloService = ProxyFactory.getProxy(HelloService.class);
//        System.out.println(helloService.hello(18));

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        Book book = new Book();
        book.setName("book1");
        book.setPrice(BigDecimal.valueOf(2.9));
        student.setBooks(Collections.singletonList(book));
        // Server配置信息
        ServerConfig serverConfig = new ServerConfig();
        ServerInstance instance = new ServerInstance();
        instance.setPort(11120);
        instance.setHost("localhost");
        serverConfig.setInstances(Collections.singletonList(instance));
        // 获取代理实例
        StudentService studentService = ReferenceProxyFactory.getProxyService(StudentService.class, serverConfig, null);
        System.out.println(studentService);
        System.out.println(studentService.update(student));
        HelloService helloService = ReferenceProxyFactory.getProxyService(HelloService.class, serverConfig, null);
        System.out.println(helloService.hello(1024));
    }
}
